package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.FocusOnTheTypeOfCompetition;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.FocusOnTheTypeOfCompetitionService;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 focusOnTheTypeOfCompetitionController
//@RequestMapping("/focusOnTheTypeOfCompetitionController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /focusOnTheTypeOfCompetitionController
public class FocusOnTheTypeOfCompetitionController {
	@Resource
	FocusOnTheTypeOfCompetitionService focusOnTheTypeOfCompetitionService;

	@GetMapping("/getAllfocusOnTheTypeOfCompetition")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<FocusOnTheTypeOfCompetition> getAllFocusOnTheTypeOfCompetition() throws Exception{
    	System.out.println("查询全部用户关注比赛类型成功");
    	return focusOnTheTypeOfCompetitionService.getAllFocusOnTheTypeOfCompetitions();
    }

	@PostMapping("/addfocusOnTheTypeOfCompetition")
	@ResponseBody
	public DTO<FocusOnTheTypeOfCompetition> addFocusOnTheTypeOfCompetition(@RequestBody FocusOnTheTypeOfCompetition focusOnTheTypeOfCompetition) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加用户关注比赛类型成功成功");
		return focusOnTheTypeOfCompetitionService.addFocusOnTheTypeOfCompetition(focusOnTheTypeOfCompetition);
	}
	@DeleteMapping("/deletefocusOnTheTypeOfCompetition/{focno}")
	@ResponseBody
    public DTO<FocusOnTheTypeOfCompetition> deleteFocusOnTheTypeOfCompetitionByFocno(@RequestBody @PathVariable("focno") String focno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(focno+"删除用户关注比赛类型成功成功");
    	return focusOnTheTypeOfCompetitionService.deleteFocusOnTheTypeOfCompetitionByFocno(focno);
    }

	@GetMapping("/focusOnTheTypeOfCompetitionBy/{focno}")
	@ResponseBody
	public DTO<FocusOnTheTypeOfCompetition> getFocusOnTheTypeOfCompetitionByFocno(@PathVariable("focno") String focno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(focno+"根据主键查询用户关注比赛类型成功成功");
		return focusOnTheTypeOfCompetitionService.getFocusOnTheTypeOfCompetitionByFocno(focno);
	}

	@PatchMapping("/updatefocusOnTheTypeOfCompetition")
	@ResponseBody
	public DTO<FocusOnTheTypeOfCompetition> updateFocusOnTheTypeOfCompetitionByFocno(@RequestBody FocusOnTheTypeOfCompetition focusOnTheTypeOfCompetition) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改用户关注比赛类型成功成功");
		System.out.println(focusOnTheTypeOfCompetition);
		return focusOnTheTypeOfCompetitionService.updateFocusOnTheTypeOfCompetitionByFocno(focusOnTheTypeOfCompetition);
	}

	@RequestMapping("/focusOnTheTypeOfCompetition/pageInfo")
	@ResponseBody
	public DTO<FocusOnTheTypeOfCompetition> getFocusOnTheTypeOfCompetitionByPage(@SpringQueryMap PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询分页");
		return focusOnTheTypeOfCompetitionService.getFocusOnTheTypeOfCompetitionByPage(pageInfo);
	}

}
